package com.example.demo.three;

import com.example.demo.util.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author chensixiang chensixiang1234@gmail.com
 */
public class Task2 {

    public static final String QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws IOException {
        Channel channel = RabbitMQUtils.getChannel();
        // 开启发布确认模式
        channel.confirmSelect();

        Scanner scanner = new Scanner(System.in);

        // 设置队列持久化
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);

        while (scanner.hasNext()) {
            String message = scanner.next();
            // 设置消息持久化
            channel.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println("消息发送成功 -> " + message);
        }
    }
}
